<?php
declare(strict_types=1);
/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://gitee.com/xmo/MineAdmin
 */

namespace Plugin\Attractions\Inspection\Repository\Inspection_device_types;

use Plugin\Attractions\Inspection\Model\Inspection_device_types\InspectionDeviceTypes;
use Hyperf\Database\Model\Builder;
use App\Repository\IRepository;
use Hyperf\Collection\Arr;

/**
 * 设备类型 Repository类
 */
class InspectionDeviceTypesRepository extends IRepository
{
   public function __construct(
        protected readonly InspectionDeviceTypes $model
    ) {}

    /**
     * 搜索处理器
     * @param Builder $query
     * @param array $params
     * @return Builder
     */
    public function handleSearch(Builder $query, array $params): Builder
    {
        
        // ID
        if (isset($params['id']) && !empty($params['id'])) {
            $query->where('id', '=', $params['id']);
        }

        // 类型名称（游乐设备、广播设备、监控设备、其他设备）
        if (isset($params['name']) && !empty($params['name'])) {
            $query->where('name', 'like', '%'.$params['name'].'%');
        }

        return $query;
    }
}